/*
 * table_CppMcrArgInfo_t.c
 *
 *  Created on: 2012/04/01
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"
/*KIND_MACROARGINFO	*/
typedef struct _MACROARGINFO
{
	S2		lArgIndex;	/* 2 */
	AST		astMacroArgStart;	/* 3 */
	AST		astMacroArgEnd;	/* 4 */
}MACROARGINFO,*PMACROARGINFO;

#define TableSize  (sizeof(MACROARGINFO))
#define TableType  PMACROARGINFO
#define stTable stMacroArgManager.memoryBlocks
#define maxTable stMacroArgManager.maxRecordNum
#define  maxNumPerBlk  (stMacroArgManager.astMaxNum_Block)

/* private field */

static TABLEMANAGER stMacroArgManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stMacroArgManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stMacroArgManager,  resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stMacroArgManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stMacroArgManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stMacroArgManager, astReqArg, resetListener );
}
static AST getMaxLineNum ( VOID )
{
	return maxTable;
}
/* give up the way that defining get/set function pointer in the struct,
 * because of memory volume.
 */
//ACCESS_S2_FIELD index;

static S2  getIndex( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->lArgIndex;
}
static S2  setIndex( AST index, S2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->lArgIndex = value;
}
//ACCESS_IDX_FIELD begin;
static AST  getFirstToken( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astMacroArgStart;
}
static AST  setFirstToken( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astMacroArgStart = value;
}
//ACCESS_IDX_FIELD end;
static AST  getLastToken( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astMacroArgEnd;
}
static AST  setLastToken( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astMacroArgEnd = value;
}
const CPPMCRARGINFO_ACCESS stCppMcrArgInfoAccess = {
//		BOOL (*clear)( VOID );
		ClearTable,
//		BOOL (*reset)( VOID );
		ResetTable,
//		BOOL (*alloc)( AST );
		AllocTable,
//		AST  (*getMax)( VOID );
		getMaxLineNum,
		{
				getIndex,
				setIndex
		},
		{
				getFirstToken,
				setFirstToken
		},
		{
				getLastToken,
				setLastToken
		}
};
